package com.thinkerwolf.dtx.seata.order.config;

import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry;
import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JCircuitBreakerFactory;
import org.springframework.cloud.client.circuitbreaker.Customizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfiguration {

  @Bean
  public Customizer<Resilience4JCircuitBreakerFactory> resilience4jCustomizer() {
    return factory -> {
      CircuitBreakerConfig config = CircuitBreakerConfig.custom().failureRateThreshold(60f).build();
      CircuitBreakerRegistry registry = CircuitBreakerRegistry.of(config);
      factory.configureCircuitBreakerRegistry(registry);
    };
  }
}
